package com.lingnan.controller;

import com.lingnan.common.utils.ResultEntity;
import com.lingnan.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zzd
 */
@Api(description = "文件上传功能")
@RestController
@RequestMapping("/ossService/file")
@CrossOrigin
public class OssController {


    @Autowired
    private OssService ossService;


    /**
     * 上传头像文件功能
     *
     * @param file 头像
     * @return
     */
    @ApiOperation(value = "上传头像文件功能")
    @PostMapping("uploading")
    public ResultEntity uploadFileAvatar(MultipartFile file) {
        // 获取上传文件 MultipartFile
        String url = ossService.uploadFileAvatar(file);
        // 获取上传后的oss路径
        return ResultEntity.ok().data("url",url);
    }

    /**
     * 上传课程封面功能
     * @param file
     * @return
     */
    @ApiOperation(value = "上传课程封面功能")
    @PostMapping("uploadCourseCover")
    public ResultEntity uploadCourseCover(MultipartFile file){
        // 获取上传文件后的url路径
        String url = ossService.uploadCourseCover(file);
        // 返回url路径
        return ResultEntity.ok().message("上传图片成功").data("url",url);



    }
}
